package com.mystyle.le.weekproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mystyle.le.weekproject.R;
import com.mystyle.le.weekproject.beans.HeadList;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by le on 2016/10/10.
 */
public class HeadListAdapter extends BaseAdapter {
    private List<HeadList> headLists;
    private Context context;

    public HeadListAdapter(List<HeadList> headLists, Context context) {
        this.headLists = headLists;
        this.context = context;
    }

    @Override
    public int getCount() {
        return headLists==null?0:headLists.size();
    }

    @Override
    public Object getItem(int position) {
        return headLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.headlist_layout,parent,false);
            holder = new ViewHolder();
            holder.headList_Img = (ImageView) convertView.findViewById(R.id.headList_Img);
            holder.headList_TV = (TextView) convertView.findViewById(R.id.headList_TV);
            holder.newsauthor_content = (TextView) convertView.findViewById(R.id.newsauthor_content);
            holder.newstype_content = (TextView) convertView.findViewById(R.id.newstype_content);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        HeadList headList = headLists.get(position);
        holder.headList_TV.setText(headList.getTitle());
        holder.newstype_content.setText(headList.getNewstype_content());
        holder.newsauthor_content.setText("\t"+headList.getNewsauthor_content());
        String cover = headList.getCover();
        holder.headList_Img.setImageResource(R.mipmap.bottombar_game_pressed);
        Picasso.with(context).load(cover).into(holder.headList_Img);
        return convertView;
    }
    class ViewHolder{
        TextView headList_TV,newstype_content,newsauthor_content;
        ImageView headList_Img;
    }
}
